package ynu.sxp.demoapp.cart.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import ynu.sxp.demoapp.common.BaseEntity;
import ynu.sxp.demoapp.user.entity.UserEntity;

import java.util.ArrayList;
import java.util.List;


@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Getter
@Setter
@Table(name = "cart")
public class CartEntity extends BaseEntity {

    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "user_id", nullable = false)
    private UserEntity user;

    @OneToMany(mappedBy = "cartId", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<CartProductEntity> cartProducts = new ArrayList<>();

    @Temporal(TemporalType.TIMESTAMP)
    private java.util.Date createdDate;

    @Temporal(TemporalType.TIMESTAMP)
    private java.util.Date updatedDate;
}
